<template>
	<FruitAdminTabbar :info="data.kindInfo.name"></FruitAdminTabbar>
	<view class="fruit-admin-item-body" :style="{marginTop:paddingT +'px'}">
		<view class="fruit-admin-item" v-for="(item,index) in data.fruitItemList" :key="index">
			<FruitAdminShowItem :fruitInfo="item" @refresh="refresh" ></FruitAdminShowItem>
		</view>
	</view>
	<image class="fruit-admin-item-add-image" src="@/page_fruit/static/fruit/add.png" mode="widthFix" @tap="goAdd"></image>
</template>

<script>
	import FruitAdminTabbar from "../components/fruit-admin-item-tabbar.vue"
	import {onLoad,onShow} from "@dcloudio/uni-app"
	import {reactive, onMounted} from 'vue'
	import global from "../../config/global.js"
	import FruitAdminShowItem from "../components/fruit-admin-show-item.vue"
	export default {
		name:"fruit-admin-item",
		components:{
			FruitAdminTabbar,
			FruitAdminShowItem
		},
		setup(){
			let data = reactive({
				kindInfo:{},
				fruitItemList:[]
			})
			let statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
			let res=wx.getMenuButtonBoundingClientRect();
			let paddingT = statusBarHeight+res.height+10;
			
			onLoad((e)=>{
				data.kindInfo = JSON.parse(decodeURIComponent(e.kindInfo))
				getData()
			})
			
			onShow(()=>{
				console.log(1)
				getData()
			})
			
			function getData(){
				uni.request({
					url:`${global.BASE_URL}/fruit/getFruitItemByKind/${data.kindInfo.id}`,
					method:"GET",
					header:{
						"mytoken":uni.getStorageSync("localtoken")
					},
					success: (res) => {
						console.log(res)
						if(res.data.code){
							data.fruitItemList = res.data.data
						}
					},
					fail: (err) => {
						console.log(err)
					}
				})
			}
			
			function refresh(e){
				getData()
			}
			
			function goAdd(){
				uni.navigateTo({
					url:"/page_fruit/fruit/fruit-admin-add-item?kindId="+data.kindInfo.id
				})
			}
			
			onMounted(()=>{
			})
			
			return {
				data,
				paddingT,
				goAdd
			}
		}
	}
</script>

<style scoped lang="scss">
	.fruit-admin-item-body{
		
	}
	
	.fruit-admin-item-add-image{
		width: 80rpx;
		position: fixed;
		right: 30rpx;
		bottom: 50rpx;
	}
</style>
